require(["common", "jQuery", "coAjax", "href"], function(jSouper, $, coAjax, href) {
	jSouper.ready(function() {
		//进入编辑状态
		App.set("$Event.personalinfo.to_edit", function(e) {
			App.set("$Cache.personalinfo.is_edit", true);
		});
		//完成编辑，提交表单
		App.set("$Event.personalinfo.post_edit", function(e) {
			coAjax.put(appConfig.user.set_info_url, App.get("loginer.info"), function(result) {
				// console.log(result);
				alert("success", "修改成功")
				App.set("loginer", result.result)
				App.set("$Cache.personalinfo.is_edit", false);
			}, function(errorCode, xhr, errorMsg) {
				switch (errorCode) {
					case "00025":
						alert("error", "登录超时");
						href.toLogin();
						break;
					case "00041":
						alert("error", "请检查您的身份证格式");
						break;
					case "00043":
						alert("error", "请检查您的邮箱格式");
						break;
					case "00044":
						alert("error", "请检查您的手机号码");
						break;
					default:
						alert("error", errorMsg);
				}
			});
		});
		//取消编辑
		App.set("$Event.personalinfo.cancel_edit", function(e) {
			coAjax.get(appConfig.user.loginer, function(result) {
				App.set("loginer", result.result);
			});
			App.set("$Cache.personalinfo.is_edit", false);
		});
	})
})

function getPath(obj) {
	if (obj) {
		var files = obj.files;
		var type = files[0].type;
		if (type === "image/jpeg" || type === "image/bmp") {
			$('img[name="img"]')[0].src = window.URL.createObjectURL(files[0])
			try {
				window.URL.revokeObjectURL(this.src);
			} catch (e) {}
		} else {
			alert('只支持.jpg, .jpeg, .bmp格式图片');
		}
	}
}